package com.steveproject.parttimeworktree.ui.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.steveproject.parttimeworktree.R;
import com.steveproject.parttimeworktree.adapter.ForwardAdapter;
import com.steveproject.parttimeworktree.base.BaseActivity;
import com.steveproject.parttimeworktree.ui.fragment.PartApplyFragment;
import com.steveproject.parttimeworktree.utils.TitleBuilder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class PartApplyActivity extends BaseActivity {
    @BindView(R.id.stl)
    SlidingTabLayout stl;
    @BindView(R.id.vp)
    ViewPager vp;
    private List<Fragment> mFragments = new ArrayList<>();
    private List<String> mTitles = new ArrayList<>();

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {

    }

    @Override
    public int intiLayout() {
        return R.layout.activity_part_apply;
    }

    @Override
    protected boolean isStatusBarBlack() {
        return true;
    }

    @Override
    public void initView() {
        new TitleBuilder(this).setTitleText("我的报名")
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });
    }

    @Override
    public void initData() {
        Intent intent = getIntent();
        //代表全部
        int type = intent.getIntExtra("type", -2);
        mTitles.add("全部");
        mTitles.add("已报名");
        mTitles.add("进行中");
        mTitles.add("已完成");
        for (int i = 0; i < mTitles.size(); i++) {
            mFragments.add(new PartApplyFragment((i + 1) + ""));
        }
        //new一个适配器
        ForwardAdapter forwardAdapter = new ForwardAdapter(getSupportFragmentManager(), mFragments, mTitles);
        //设置ViewPager与适配器关联
        vp.setAdapter(forwardAdapter);
        vp.setOffscreenPageLimit(mTitles.size() - 1);
        //设置Tab与ViewPager关联
        stl.setViewPager(vp);
        switch (type) {
            case -2://全部
                stl.setCurrentTab(0);
                break;
            case -1://已报名
                stl.setCurrentTab(1);
                break;
            case 0://进行中
                stl.setCurrentTab(2);
                break;
            case 1://已完成
                stl.setCurrentTab(3);
                break;
        }

    }
}
